//
//  SocialPhotoBrowserCell.m
//  ShowYork
//
//  Created by hxh on 2020/9/23.
//  Copyright © 2020 hxh. All rights reserved.
//

#import "CampusPicBroswerCell.h"

@interface CampusPicBroswerCell ()<UIScrollViewDelegate>
@property (nonatomic,strong)UIScrollView *scrollView;
@property (nonatomic,strong)UIImageView *containImgView;
@end

@implementation CampusPicBroswerCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self setUI];
    }
    return self;
}

- (void)setUI{
    
    self.scrollView = [[UIScrollView alloc]init];
    self.scrollView.backgroundColor = [UIColor clearColor];
    self.scrollView.contentSize = CGSizeMake(kScreenW,kScreenH - kNavBarHeight);
    self.scrollView.delegate = self;
    self.scrollView.showsHorizontalScrollIndicator = NO;
    self.scrollView.showsVerticalScrollIndicator = NO;
    self.scrollView.minimumZoomScale = 1;
    self.scrollView.maximumZoomScale = 3;
    
    [self.scrollView setZoomScale:1.0];
    
    [self.contentView addSubview:self.scrollView];
      
    self.containImgView = [[UIImageView alloc]init];
    self.containImgView.userInteractionEnabled = YES;
    self.containImgView.contentMode = UIViewContentModeScaleAspectFit;
    [self.scrollView addSubview:self.containImgView];
    
    
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.left.right.equalTo(self.contentView);
    }];
    
    [self.containImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.scrollView);
        make.size.mas_equalTo(CGSizeMake(kScreenW, kScreenH - kNavBarHeight));
    }];
}



- (void)setItemModel:(CampusSchoolPictureItemModel *)itemModel{
    _itemModel = itemModel;
    [self.containImgView sd_setImageWithURL:[NSURL URLWithString:itemModel.cover] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        if (image != nil) {
            itemModel.loadImage = image;
        }
    }];
    [self.scrollView setZoomScale:1.0f];
}

-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
    
   for (UIView *v in scrollView.subviews){
       return v;
    }
    return nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if(interfaceOrientation ==UIInterfaceOrientationPortrait||interfaceOrientation ==UIInterfaceOrientationPortraitUpsideDown)
    {
       return YES;
    }
    return NO;
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{

//    if (scrollView ==self.imageScrollView){
//
//        NSInteger index = scrollView.contentOffset.x/kScreenW;
//        self.pageControl.currentPage = index;
//
//        self.currentModel.imageCurrentIndex = index;
//
//        CGFloat x = scrollView.contentOffset.x;
//        if (x==-kScreenW){
//
//        }else{
//            for (UIScrollView *s in scrollView.subviews){
//                if ([s isKindOfClass:[UIScrollView class]]){
//                    [s setZoomScale:1.0]; //scrollView每滑动一次将要出现的图片较正常时候图片的倍数（将要出现的图片显示的倍数）
//                }
//            }
//        }
//    }
}

@end
